import axios from '../http/axios'

//热点
export const getre = (page: number) => {
  return axios.get('/v1/cooperation/wap/health_news/', {
    params: {
      from_wx_mini: '1',
      page: page,
      partner: 'chunyu_wap_mini',
      release_time: '2020-04-22',
      channel_id: '0'
    }
  })
}

//普通
export const getpu = (page: number) => {
  return axios.get('v1/cooperation/wap/topic_check_list/', {
    params: {
      page: page
    }
  })
}

//生活
export const getshen = (page: number) => {
  return axios.get('v1/cooperation/wap/health_news/', {
    params: {
      from_wx_mini: '1',
      page: page,
      partner: 'chunyu_wap_mini',
      release_time: '2020-04-22',
      channel_id: '21'
    }
  })
}

//母婴
export const getmu = (page: number) => {
  return axios.get('v1/cooperation/wap/health_news/', {
    params: {
      from_wx_mini: '1',
      page: page,
      partner: 'chunyu_wap_mini',
      release_time: '2020-04-22',
      channel_id: '6'
    }
  })
}

//辟谣
export const getpi = (page: number) => {
  return axios.get('v1/cooperation/wap/health_news/', {
    params: {
      from_wx_mini: '1',
      page: page,
      partner: 'chunyu_wap_mini',
      release_time: '2020-04-22',
      channel_id: '18'
    }
  })
}

//春雨热卖
export const getfu = (from_wx_mini: number) => {
  return axios.get('v1/api/v8/user_home_page/hot_sales_v2/', {
    params: {
      from_wx_mini: from_wx_mini
    }
  })
}

//春雨推荐
export const getdata = (from_wx_mini: number, need_ab_test: number, abtest_v2: number) => {
  return axios.get('v1/cooperation/wap/homepage_info/', {
    params: {
      from_wx_mini: from_wx_mini,
      need_ab_test: need_ab_test,
      abtest_v2: abtest_v2,
      version: '10.6.8',
      device_id: 'oOKH50Osc-tkNqwuSmwa0ktH4aV4'
    }
  })
}

//热搜
export const getrs = () => {
  return axios.get('v1/api/search/recommend_tag/', {
    params: {
      from_type: 'home_search',
      version: '10.6.8'
    }
  })
}

//医生
export const getdocter = () => {
  return axios.get('v1/api/search/news/selected_doctor/', {
    params: {
      news_id: '203845',
    }
  })
}

//底部详情
export const gettabbar = (id: string) => {
  return axios.get(`/v1/cooperation/wap/article/${id}/`, {
    params: {
      partner: 'chunyu_wap_mini',
      promote: 0
    }
  })
}

//实时搜索
export const getshi = (string: string) => {
  return axios.get('v1/api/v8/search/new_suggestion/', {
    params: {
      version: '10.6.8',
      type: 'big_search',
      query: string,
    }
  })
}

//国家
export const getjigou = () => {
  return axios.get('/v1/cooperation/wap/homepage_info/', {
    params: {
      from_wx_mini: 1,
      need_ab_test: 1,
      abtest_v2: 1,
      version: '10.6.8',
      device_id: 'oOKH50Osc-tkNqwuSmwa0ktH4aV4'
    }
  })
}

//商城搜索上下滚动
export const getcartscrroll = () => {
  return axios.get('v1/mall/search/hot_search_keywords/')
}
// 商城导航菜单
export const getcaidan = () => {
  return axios.get('v1/mall/goods/category/info/')
}
// 商城搜索上下滚动
export const getsousuo = () => {
  return axios.get('v1/mall/search/hot_search_keywords/')
}
// 商城健康护肤
export const gethufu = () => {
  return axios.get('v1/mall/home/recommend_big_card/')
}
// 商城健康体检
export const gettijian = () => {
  return axios.get('v1/mall/home/recommend_small_card/')
}
// 商城列表
export const getlist = () => {
  return axios.get('v1/mall/home/shop_spu/content_config/', {
    params: {
      cursor: 1,
      page_size: 20
    }
  })
}
//药品详情
export const getlistdetail = (shop_spu_id: string) => {
  return axios.get('/v1/mall/shop_spu/detail/base/', {
    params: {
      shop_spu_id: shop_spu_id
    }
  })
}
//药品图片
export const getlistimg = (shop_spu_id: string) => {
  return axios.get('/v1/mall/shop_spu/detail/tail/', {
    params: {
      shop_spu_id: shop_spu_id
    }
  })
}
//注册
export const getregister = (
  username: string,
  password: string,
  nickname: string,
  avatar: string
) => {
  return axios.post('/api/register', {
    username,
    password,
    nickname,
    avatar
  })
}
//登录
export const getlogin = (username: string, password: string) => {
  return axios.post('/api/login', {
    username,
    password
  })
}

interface address {
  tel: string
  nickname: string
  provice_city_area: string
  detail_address: string
  longitude: string
  latitude: string
}
//新增地址
export const getaddress = (data: address) => {
  return axios.put('/api/v1/address', data)
}
//获取地址
export const getaddresslist = () => {
  return axios.get('/api/v1/address')
}
//渲染地址
export const geteditaddress = (id: string) => {
  return axios.get(`/api/v1/address/${id}`, {
    params: {
      id
    }
  })
}
//删除地址
export const getedeleteaddress = (id: string) => {
  return axios.delete(`/api/v1/address/${id}`, {
    params: {
      id
    }
  })
}
//编辑地址
export const getgaiaddress = (
  // id: string,
  tel: string,
  nickname: string,
  provice_city_area: string,
  detail_address: string,
  longitude: string,
  latitude: string
) => {
  return axios.post('/api/v1/address', {
    tel,
    nickname,
    provice_city_area,
    longitude,
    latitude,
    detail_address
  })
}

// src/config/oss.js
export const OSS_CONFIG = {
  region: 'http://zhwg6.oss-cn-beijing.aliyuncs.com', // e.g. 'oss-cn-hangzhou'
  accessKeyId: 'LTAI5tABjqyyd3azF5PPDVdZ',
  accessKeySecret: '96B7GZec9TRViNKJ7b5iM33uuphilj',
  bucket: 'zhwg6'
}
//下单
export const place = (goods: Array<object>, address: object, totalPrice: number) => {
  const now = new Date();
  const createTime = now.toISOString().slice(0, 19).replace('T', ' ');
  return axios.post('/api/v1/place/order', {
    createTime: createTime,
    goods,
    address,
    totalPrice
  })
}
//支付
// id title price body
export const payment = (id: string) => {
  return axios.post('/api/v1/payment', {
    id,
    returnUrl: 'http://localhost:5173/home'
  })
}
//订单列表 
export const orderlist = (state: string) => {
  return axios.get('/api/v1/order', {
    params: {
      state
    }
  })
}
//删除订单
export const orderdetail = (id: string) => {
  return axios.delete('/api/v1/order', {
    params: {
      id
    }
  })
}
//查询支付状态 
export const orderstatus = (out_trade_no: string) => {
  return axios.get('/api/v1/order/query', {
    params: {
      out_trade_no
    }
  })
}
